#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N];
int st[N], top;
bool solve() {
  cin >> n;
  if (!n) return false;
  rep(i, 1, n) cin >> a[i];
  a[++n] = -1;
  ll ans = 0;
  top = 0;
  rep(i, 1, n) {
    while (top && a[st[top]] >= a[i]) {
      int j = st[top];
      top--;
      int h = a[j];
      int right = i;
      int left = (top ? st[top] : 0) + 1;
      int w = right - left;
      ans = max(ans, 1ll * w * h);
    }
    st[++top] = i;
  }
  cout << ans << endl;
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (solve());
  return 0;
}